<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会员等级权益列表')"/>
    <th:block th:include="include :: bootstrap-editable-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <input type="hidden" name="systemModule" id="systemModule" value="0"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <p style="width: 90px;">会员等级：</p>
                            <select name="memberVipTypeId" th:with="vipTypeList=${vipTypeList}">
                                <option value="">全部</option>
                                <option th:each="type:${vipTypeList}" th:value="${type.id}"
                                        th:text="${type.vipTypeName}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<script th:inline="javascript">
    var prefix = ctx + "back/shopMemberVipBenefit";
    $(function () {
        var options = {
            url: prefix + "/searchList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "充值权益",
            sortName: "mvb.memberVipTypeId asc,sp.productPrice",
            sortOrder: "asc",
            onEditableSave: onEditableSave,
            columns: [
                {
                    field: 'id',
                    title: '权益ID',
                    visible:false
                },
                {
                    field: 'vipTypeName',
                    title: '等级名称',
                    sortable: true
                },
                {
                    field: 'price',
                    title: '充值金额'
                },
                {
                    field: 'isCredit',
                    title: '是否送积分',
                    sortable: true,
                    visible:false,
                    editable: {
                        type: 'select',
                        title: '状态',
                        source: [{
                            value: 1,
                            text: "是"
                        }, {
                            value: 0,
                            text: "否"
                        }]
                    }
                },
                {
                    field: 'benefitCredit',
                    title: '赠送固定积分',
                    sortable: true,
                    visible:false,
                    editable: {
                        type: 'text',
                        title: '赠送固定积分',
                        emptytext: "【赠送固定积分】不能为空",
                        validate: function (v) {
                            if ($.trim(v) == '') {
                                return '【赠送固定积分】不能为空!';
                            }
                            if (isNaN(v)) {
                                return '【赠送固定积分】必须是数字';
                            }
                            if (!(/(^[1-9]\d*$)/.test(v))) {
                                return '请输入正确的【赠送固定积分】';
                            }
                        }
                    }
                },
                {
                    field: 'isAmount',
                    title: '是否赠送金额',
                    sortable: true,
                    editable: {
                        type: 'select',
                        title: '状态',
                        source: [{
                            value: 1,
                            text: "是"
                        }, {
                            value: 0,
                            text: "否"
                        }]
                    }
                },
                {
                    field: 'benefitAmount',
                    title: '赠送固定金额',
                    sortable: true,
                    editable: {
                        type: 'text',
                        title: '赠送固定金额',
                        emptytext: "【赠送固定金额】不能为空",
                        validate: function (v) {
                            if ($.trim(v) == '') {
                                return '【赠送固定金额】不能为空!';
                            }
                            if (isNaN(v)) {
                                return '【赠送固定金额】必须是数字';
                            }
                            if (!(/(^[1-9]\d*$)/.test(v))) {
                                return '请输入正确的【赠送固定金额】';
                            }
                        }
                    }
                },
                {
                    field: 'isEnable',
                    title: '权益状态',
                    sortable: true,
                    editable: {
                        type: 'select',
                        title: '权益状态',
                        source: [{
                            value: 1,
                            text: "正常"
                        }, {
                            value: 0,
                            text: "停用"
                        }]
                    }
                },
            ]
        };
        $.table.init(options);
    });
    function onEditableSave(field, row) {
        let updateData = {};
        updateData[field] = row[field];
        updateData.id = row.id;
        updateData.systemModule = $('#systemModule').val();
        $.ajax({
            type: 'post',
            url: ctx + "back/shopMemberVipBenefit/edit",
            data: updateData,
            dataType: 'json',
            async: false,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess("修改成功");
                } else {
                    $.modal.alertError(result.msg);
                }
                $.table.refresh();
            },
            error:function(){
                $.table.refresh();
            }
        });
    }
</script>
</body>
</html>